<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<c:set var="ctx" value="${pageContext.request.contextPath}"></c:set>
<!DOCTYPE html>
<html lang="zh">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>班级信息</title>
<link rel="stylesheet" href="${ctx}/statics/css/bootstrap.min.css" />
<link rel="stylesheet" href="${ctx}/statics/css/font-awesome.min.css" />
<link rel="stylesheet" href="${ctx}/statics/js/layer/skin/default/layer.css" />
<link rel="stylesheet" href="${ctx}/statics/js/bootstrap-table/bootstrap-table.css" />
<link rel="stylesheet" href="${ctx}/statics/js/toastr/toastr.css" />
</head>
<body>
	<!-- 添加和编辑模态窗口 -->
	<div class="modal fade" id="entityModal" role="dialog"
		aria-labelledby="userModelLabel" aria-hidden="true"
		data-backdrop="false">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
					<h4 class="modal-title">添加班级</h4>
				</div>
				<div class="modal-body">
					<form id="entity_edit_form" class="form-horizontal">
						<input type="hidden" id="id" name="id">
						<div class="form-group">
							<label class="control-label col-sm-3">班级名称：</label>
							<div class="col-sm-8">
								<input type="text" class="form-control col-sm-3"
									name="className">
							</div>
						</div>
						
						<!-- <div class="form-group">
							<label class="control-label col-sm-3">班级学习方向：</label>
							<div class="col-sm-8">
								<input type="text" class="form-control col-sm-3"
									name="classSubject">
							</div>
						</div> -->
						
						<div class="form-group">
						<label class="control-label col-sm-3">班级学习方向：</label>
						<div class="col-sm-8">
							<select class="form-control" id="subjectId"  name="subjectId">
							</select>
						</div>
					</div>
						
						
						<div class="form-group">
							<label class="control-label col-sm-3">班级学习费用：</label>
							<div class="col-sm-8">
								<input type="text" class="form-control col-sm-3"
									name="cost">
							</div>
						</div>
						
						<div class="form-group">
							<label class="control-label col-sm-3">班级学习内容：</label>
							<div class="col-sm-8">
									<textarea class="form-control col-sm-3" rows="3" cols="1" name="classContent"></textarea>
							</div>
						</div>
						
						<div class="form-group">
						<label class="control-label col-sm-3">开始时间：</label>
						<div class="col-sm-8">
							<input type="date" id="birthDay" class="form-control col-sm-3"
								name="startTime">
						</div>
					</div>
					<div class="form-group">
						<label class="control-label col-sm-3">结束时间：</label>
						<div class="col-sm-8">
							<input type="date" id="birthDay" class="form-control col-sm-3"
								name="endTime">
						</div>
					</div>
					</form>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-sm btn-primary"
						id="entityModalBtn">确定</button>
					<button type="button" class="btn btn-sm btn-default"
						data-dismiss="modal" id="Close">关闭</button>
				</div>
			</div>
		</div>
	</div>
	<div id="main-content">
		<div class="row">
			<div class="col-md-12">
				<div class="panel panel-default">
					<div class="panel-heading">班级信息</div>
					<!-- /.panel-heading -->
					<div class="panel-body">
						<!-- 搜索                                                                -->
						<div class="row">
							<div class="col-xs-12">
								<!-- PAGE CONTENT BEGINS -->
								<form class="form-horizontal" role="form"
									id="entity_search_form">
									<div class="form-group">
										<div class="col-sm-4">
											<div class="input-group  ">
												<span class="input-group-addon"> <i class="icon-home"></i>
												</span> <input class="form-control input-mask-phone" type="text"
													id="form-field-mask-2" name="className"
													placeholder="班级名称">
											</div>
										</div>
										<div class="col-sm-1">
											<button class="btn btn-sm btn-info" type="submit">
												<i class="icon-search nav-search-icon"></i> 查询
											</button>
										</div>
										<div class="col-sm-1">
											<button class="btn btn-sm btn-primary" type="reset">
												<i class="icon-undo bigger-110"></i> 清除
											</button>
										</div>
									</div>
								</form>
							</div>
						</div>
						<!-- 搜索                                                                -->
						<!-- 添加                                                                -->
						<div id="entity_table_tools">
							<!-- id="advertisement_table_tools" -->
							<div class="text-right">
								<button type="button" class="btn btn-success btn-sm"
									onclick="addData()">新增班级</button>
							</div>
						</div>
						<!-- 添加                                                                -->
						<!-- 主体表格                                                                -->
						<table id="entity_table" class="table table-bordered table-hover">
							<!-- id="user_table" -->
						</table>
						<!-- 主体表格                                                                -->
					</div>
					<!-- panel body -->
				</div>
			</div>
		</div>
	</div>
	<%@ include file="../common.jsp"%>
	<script type="text/javascript"
		src="${ctx}/statics/js/jquery-form/jquery.form.js"></script>
</body>
<script type="text/javascript">
var rolePower = "${rolePower}";
var rp = rolePower == 1 ? true : false;
	$(function() {
		getSubjects();
		$('#entity_table')
				.bootstrapTable(
						{
							url : '${ctx}/class/getList.do',
							pagination : true,
							paginationLoop : false,
							smartDisplay : false,
							striped : true,
							pageSize : 10,
							pageList : [ 10, 20, 50, 100 ],
							sidePagination : 'server',
							showRefresh : false,
							showColumns : false,
							paginationNextText : '下一页',
							paginationPreText : '上一页',
							cache : false,
							columns : [
									{
										field : 'id',
										title : 'ID',
										width : 50
									},
									{
										field : 'className',
										title : '班级名称',
										width : 50
									},
									{
										field : 'classSubject',
										title : '班级学习方向',
										width : 50
									},
									{
										field : 'classContent',
										title : '班级学习内容',
										width : 400
									},
									{
										field : 'cost',
										title : '学习费用',
										width : 30
									},
									{
										field : 'startTime',
										title : '开始时间',
										width : 80
									},
									{
										field : 'endTime',
										title : '结束时间',
										width : 80
									},
									{
										field : 'createor',
										title : '创建人',
										width : 80
									},{
										field : '',
										title : '操作',
										align : 'center',
										width : 10,
										formatter : function(value, row, index) {
											return '<div class="visible-md visible-lg hidden-sm hidden-xs btn-group">'
													+ '<button class="btn btn-xs btn-info" id="editData"  title="编辑"><i class="icon-edit bigger-130"></i></button>'
													+ '<button class="btn btn-xs btn-danger" id="deleteData" title="删除"><i class="icon-trash bigger-130"></i></button></div>';
										},
										events : {
											'click #editData' : editData,
											'click #deleteData' : deleteData,
										}

									} ],
							queryParams : function(params) {
								$.extend(params, $("#entity_search_form")
										.serializeJson());
								return params;
							}
						});

		$("#entity_search_form").submit(function(e) {
			e.preventDefault();
			$('#entity_table').bootstrapTable('refresh');
		});

	});

	function editData(e, v, row) {
		if (rp) {
			alert("当前用户权限不够");
			return;
		}
		$("#entityModal .modal-title").empty().html("修改班级信息");
		$("#entity_edit_form")[0].reset();
		$("#entity_edit_form input[name=id]").val(row.id);
		$("#entity_edit_form input[name=className]").val(row.className);
		$("#subjectId").val(row.subjectId);
		
		$("textarea").val(row.classContent);
		$("#entity_edit_form input[name=cost]").val(row.cost);
		$("#entity_edit_form input[name=startTime]").val(row.startTime);
		$("#entity_edit_form input[name=endTime]").val(row.endTime);
		$('#entityModal').modal('show');
	}
	function deleteData(e, v, row) {
		if (rp) {
			alert("当前用户权限不够");
			return;
		}
		var r = confirm("你确定删除该班级吗？");
		if (r) {
			$.ajax({
				url : "${ctx}/class/deleteDataById.do",
				type : "POST",
				data : {
					"id" : row.id
				},
				success : function(data) {
					if (data.success) {
						$('#entity_table').bootstrapTable('refreshOptions', {
							pageNumber : 1
						});
					} else {
						alert(data.errorMessage);
					}
				}
			});
		}
	}
	function addData(e, v, row) {
		$("#entity_edit_form")[0].reset();
		$("#entityModal .modal-title").empty().html("添加班级");
		$("#entity_edit_form input[name=id]").val("");
		$('#entityModal').modal('show');
	}
	$("#entityModal").on('click', '#entityModalBtn', function() {
		var result = checkForm();
		if (!result) {
			return false;
		}
		$.ajax({
			url : "${ctx}/class/saveOrUpdate.do",
			type : "POST",
			data : $("#entity_edit_form").serialize(),
			success : function(data) {
				if (data.success == true) {
					$('#entityModal').modal('hide')
					$('#entity_table').bootstrapTable('refresh');
				} else {
					alert(data.errorMessage);
				}
				$("#entityModal").prop("disabled", false);
			}
		});
	});
	function checkForm() {
		var subjectId = $("#subjectId").val();
		if (subjectId==null||subjectId=='') {
			//toastr.warning("请填用户名称");
			alert("请填班级学习方向");
			return false;
		}
		var classContent = $("textarea").val();
		if (classContent.trim().length < 1) {
			//toastr.warning("请填用户名称");
			alert("请填班级学习内容");
			return false;
		}
		var startTime=$("#entity_edit_form input[name=startTime]").val();
		if (startTime==null||startTime=='') {
			//toastr.warning("请填用户名称");
			alert("开始时间不能为空");
			return false;
		}
		var endTime=$("#entity_edit_form input[name=endTime]").val();
		if (endTime==null||endTime=='') {
			//toastr.warning("请填用户名称");
			alert("结束时间不能为空");
			return false;
		}
		return true;
	}
	function getSubjects(){
		$.ajax({
			url : "${ctx}/classSubject/getAllList.do",
			type : "GET",
			data : {},
			success : function(data) {
				if(data.success) {
					var html="<option value=''>请选择班级方向</option>"  ;
					for(var i=0;i<data.result.length;i++){
						html=html+"<option value='"+data.result[i].id+"'>"+data.result[i].subjectName+"</option>"
					}
					$("#subjectId").html(html);
				}else {
					alert(data.errorMessage);
				}				
			}
		});
	}
	
	
</script>
</html>